import { CREATE_ITEMBANK,SET_ITEMBANK_LIST,SET_ITEMBANK_RELATED_QUESTIONS,REMOVE_ITEMBANK} from '../actions/types';

const initialState = {
  createBankSuccessful: false,
  itembanks:[],
  related_questions:[],
};

export default (state = initialState, action = {}) => {
  switch(action.type) {
    case CREATE_ITEMBANK:
      return {
        createBankSuccessful: action.result,
      };
    case SET_ITEMBANK_LIST:
      return {
        itembanks: action.itembanks
      };
    case SET_ITEMBANK_RELATED_QUESTIONS:
      return Object.assign({}, state, {
        related_questions: action.questions
      });
    case REMOVE_ITEMBANK:
      var new_items = state.itembanks.filter((value)=>{
         return action.itembank === value.id 
      });
      return  Object.assign({}, state, {
            itembanks: new_items
        });
    default: return state;
  }
}
